package com.xszx.serviceedu.controller;


import com.xszx.commonutils.R;
import com.xszx.serviceedu.entity.form.VideoInfoForm;
import com.xszx.serviceedu.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author 白熊
 * @since 2024-07-17
 */
@RestController
@RequestMapping("/serviceedu/video")
//@CrossOrigin
@Api(tags = "节目录管理")
public class VideoController {
    @Autowired
    private VideoService videoService;

    @GetMapping("{id}")
    @ApiOperation("根据id获取节目录信息")
    public R getVideInfoById(@ApiParam(name = "id",value = "节目录id",required = true)
                                         @PathVariable String id){
        VideoInfoForm videoInfoForm = videoService.getVideoInfoFormById(id);
        return R.ok().data("item",videoInfoForm);
    }

    @DeleteMapping("{id}")
    @ApiOperation("删除节目录")
    public R removeById(@ApiParam(value = "节目录id",name = "id",required = true)
                                    @PathVariable String id) throws InterruptedException {
//        Thread.sleep(10000);
        boolean b = videoService.removeVideoById(id);
        if(b){
            return R.ok().message("删除节目录成功");
        }else {
            return R.error().message("删除节目录失败");
        }
    }

    @PutMapping("{id}")
    @ApiOperation("修改节目录信息")
    public R updateCourseInfoById(@ApiParam(value = "节目录id",name = "id",required = true)
                                      @PathVariable String id,
                                  @ApiParam(name = "videoInfoForm",value = "节目录对象",required = true)
                                  @RequestBody VideoInfoForm videoInfoForm){
        videoService.updateVideoInfoById(videoInfoForm);
        return R.ok().message("节目录修改成功!");
    }

    @PostMapping
    @ApiOperation("添加节目录")
    public R save(@ApiParam(value = "节目录对象",name = "videoInfoForm",required = true)
                      @RequestBody VideoInfoForm videoInfoForm){
        videoService.saveVideoInfo(videoInfoForm);
        return R.ok().message("节目录保存成功1");
    }
}

